function FixTable(TableID, FixColumnNumber, width, height) {
    //TableID            要锁定的Table的ID
    //FixColumnNumber    要锁定列的个数
    //width              显示的宽度
    //height             显示的高度
    if ($("#" + TableID + "_tableLayout").length != 0) {
        $("#" + TableID + "_tableLayout").before($("#" + TableID));
        $("#" + TableID + "_tableLayout").empty();
    } else {
        $("#" + TableID).after("<div id='" + TableID + "_tableLayout' style='overflow:hidden;'></div>");
    }
    $('<div id="' + TableID + '_tableFix"></div>'
        + '<div id="' + TableID + '_tableHead"></div>'
        + '<div id="' + TableID + '_tableColumn"></div>'
        + '<div id="' + TableID + '_tableData"></div>').appendTo("#" + TableID + "_tableLayout");
    var oldtable = $("#" + TableID);
    var tableFixClone = oldtable.clone(true);
    tableFixClone.attr("id", TableID + "_tableFixClone");
    $("#" + TableID + "_tableFix").append(tableFixClone);
    var tableHeadClone = oldtable.clone(true);
    tableHeadClone.attr("id", TableID + "_tableHeadClone");
    $("#" + TableID + "_tableHead").append(tableHeadClone);
    var tableColumnClone = oldtable.clone(true);
    tableColumnClone.attr("id", TableID + "_tableColumnClone");
    $("#" + TableID + "_tableColumn").append(tableColumnClone);
    $("#" + TableID + "_tableData").append(oldtable);
    $("#" + TableID + "_tableLayout table").each(function () {
        $(this).css("margin", "0");
    });
    var HeadHeight = $("#" + TableID + "_tableHead thead").height();
    HeadHeight += 2;
    $("#" + TableID + "_tableHead").css("height", HeadHeight);
    $("#" + TableID + "_tableFix").css("height", HeadHeight);
    var ColumnsWidth = 0;
    var ColumnsNumber = 0;
    $("#" + TableID + "_tableColumn tr:last td:lt(" + FixColumnNumber + ")").each(function () {
        ColumnsWidth += $(this).outerWidth(true);
        ColumnsNumber++;
    });
    ColumnsWidth += 2;
    if ($.browser.msie) {
        switch ($.browser.version) {
            case "7.0":
                if (ColumnsNumber >= 3) ColumnsWidth--;
                break;
            case "8.0":
                if (ColumnsNumber >= 2) ColumnsWidth--;
                break;
        }
    }
    $("#" + TableID + "_tableColumn").css("width", ColumnsWidth);
    $("#" + TableID + "_tableFix").css("width", ColumnsWidth);
    $("#" + TableID + "_tableData").scroll(function () {
        $("#" + TableID + "_tableHead").scrollLeft($("#" + TableID + "_tableData").scrollLeft());
        $("#" + TableID + "_tableColumn").scrollTop($("#" + TableID + "_tableData").scrollTop());
    });
    $("#" + TableID + "_tableFix").css({
        "overflow": "hidden",
        "position": "relative",
        "z-index": "50",
        "background-color": "white"
    });
    $("#" + TableID + "_tableHead").css({
        "overflow": "hidden",
        "width": width - 17,
        "position": "relative",
        "z-index": "45",
        "background-color": "white"
    });
    $("#" + TableID + "_tableColumn").css({
        "overflow": "hidden",
        "height": height - 17,
        "position": "relative",
        "z-index": "40",
        "background-color": "white"
    });
    $("#" + TableID + "_tableData").css({
        "overflow": "scroll",
        "width": width,
        "height": height,
        "position": "relative",
        "z-index": "35"
    });
    if ($("#" + TableID + "_tableHead").width() > $("#" + TableID + "_tableFix table").width()) {
        $("#" + TableID + "_tableHead").css("width", $("#" + TableID + "_tableFix table").width());
        $("#" + TableID + "_tableData").css("width", $("#" + TableID + "_tableFix table").width() + 17);
    }
    if ($("#" + TableID + "_tableColumn").height() > $("#" + TableID + "_tableColumn table").height()) {
        $("#" + TableID + "_tableColumn").css("height", $("#" + TableID + "_tableColumn table").height());
        $("#" + TableID + "_tableData").css("height", $("#" + TableID + "_tableColumn table").height() + 17);
    }
    $("#" + TableID + "_tableFix").offset($("#" + TableID + "_tableLayout").offset());
    $("#" + TableID + "_tableHead").offset($("#" + TableID + "_tableLayout").offset());
    $("#" + TableID + "_tableColumn").offset($("#" + TableID + "_tableLayout").offset());
    $("#" + TableID + "_tableData").offset($("#" + TableID + "_tableLayout").offset());
}

let w = $('.box').width();
let h = $('.box').height();
FixTable("table1", 3, w, h);
window.onresize = function () {
    let w = $('.box').width();
    let h = $('.box').height();
    FixTable("table1", 3, w, h);
}

$('tbody td').click(function () {
    var className1 = $(this).children().attr("class");

    if (className1 == "div1") {
        $(this).children().addClass("divCol1");
        $(this).next().children().removeClass("divCol2")
        $(this).next().next().children().removeClass("divCol3")
    } else if (className1 == "div2") {
        $(this).children().addClass("divCol2");
        $(this).prev().children().removeClass("divCol1")
        $(this).next().children().removeClass("divCol3")
    } else if (className1 == "div3") {
        $(this).children().addClass("divCol3");
        $(this).prev().prev().children().removeClass("divCol1")
        $(this).prev().children().removeClass("divCol2")

    }
    let num = $(this).children().parents('tr').children().eq(0).text(); // 该行中的序号的文本
    let yian = $(this).children().attr('name'); // 第几个议案
    let val = $(this).children().attr("valuea"); // 议案的意见
    let data = {
        num: num,
        yian: yian,
        val: val
    };
    console.log("data", data);
    $.ajax({
        type: 'POST',
        url: '/jilutable',
        data: data,
        success: function () {
            console.log('修改成功！');
        },
        error:function () {
            console.log('修改失败！请稍后再试');
        }
    })
})

function clear1() {
    var xuhao = sessionStorage.getItem("xuhao");
    var data = {
        xuhao:xuhao
    }
    if (confirm('确定要删除该行记录吗?')) {
        $.ajax({
            type: 'POST',
            url: '/jilutable/clear',
            data: data,
            success: function () {
                location.href = '/jilutable';
            },
            error: function () {
                alert('清除失败！请查看电脑是否联网...');
            }
        })
    }
}

var tableId = document.getElementById('table1_tableLayout');
var trs = tableId.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++) {
    (function (i) {
        trs[i].oncontextmenu = function (e) {
            var xuhao = $(this).children("td").eq(0).text();
            sessionStorage.setItem("xuhao", xuhao);
            if (window.event) e = window.event;
            var mymenu = document.getElementById("menutab");
            mymenu.style.visibility = "visible";
            mymenu.style.left = e.clientX + 0 + "px";
            mymenu.style.top = e.clientY + 0 + "px";
            return false;
        }
    })(i)
}
document.onclick = function () {
    var mymenu = document.getElementById("menutab");
    mymenu.style.visibility = "hidden";
}

function Statistics() {
    location.href = '/tongji';
}

//搜索框功能
function myFunction() {
    // 声明变量
    var input, filter, table, tr, td, i;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("table1_tableLayout");
    tr = table.getElementsByTagName("tr");

    // 循环表格每一行，查找匹配项
    for (i = 0; i < tr.length; i++) {
        td = tr[i].getElementsByTagName("td")[0];
        if (td) {
            if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                tr[i].style.display = "";
            } else {
                tr[i].style.display = "none";
            }
        }
    }
}